package com.financing.platform.web.api;

import java.util.Collections;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.platform.common.Pager;
import com.financing.platform.common.ResultCode;
import com.financing.platform.common.ResultMap;
import com.financing.platform.dto.FpFaUserDataDTO;
import com.financing.platform.service.IFpFaUserDataService;
import com.financing.platform.util.DTOdateSet;

@Controller("fpFaUserDataController")
@RequestMapping("/api/fpFaUserData")
public class FpFaUserDataController extends BaseAction  { 

	private Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private IFpFaUserDataService fpFaUserDataService;
	
	@RequestMapping("/listFpFaUserData")
	@ResponseBody
	public ResultMap list(HttpServletRequest request, FpFaUserDataDTO fpFaUserData,Pager pager){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("query fpFaUserData list begin .......");
			
			fpFaUserData.setBegin(pager.getStartIndex());
			fpFaUserData.setPageSize(pager.getPageSize());
			
			int count = fpFaUserDataService.queryListCount(fpFaUserData);
			
			pager.setTotalCount(count);
			
			List<FpFaUserDataDTO> fpFaUserDataList = null;
			
			if(count > 0){
				fpFaUserDataList = fpFaUserDataService.queryList(fpFaUserData);
			}else{
				fpFaUserDataList = Collections.emptyList();
			}
			result.setAttribute("pager", pager);
			result.setAttribute("list", fpFaUserDataList);
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("query fpFaUserData list end .......");
		}catch(Exception e){
			log.error("query fpFaUserData error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	@RequestMapping("/addFpFaUserData")
	@ResponseBody
	public ResultMap add(HttpServletRequest request, FpFaUserDataDTO fpFaUserData){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("add fpFaUserData  begin .......");
			
			DTOdateSet.setCreateInfo(fpFaUserData,request.getSession());
			DTOdateSet.setUpdateInfo(fpFaUserData,request.getSession());
			
			int id = fpFaUserDataService.insert(fpFaUserData);
			result.setAttribute("id", id);
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("add fpFaUserData list end .......");
		}catch(Exception e){
			log.error("add fpFaUserData error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	
	@RequestMapping("/detailFpFaUserData")
	@ResponseBody
	public ResultMap detail(HttpServletRequest request, FpFaUserDataDTO fpFaUserData){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("query detail fpFaUserData  begin .......");
			
			
			FpFaUserDataDTO dto = fpFaUserDataService.loadById(fpFaUserData.getId());
			
			result.setAttribute("dto",dto);
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("query detail fpFaUserData  end .......");
		}catch(Exception e){
			log.error("query detail fpFaUserData error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	@RequestMapping("/deleteFpFaUserData")
	@ResponseBody
	public ResultMap delete(HttpServletRequest request, FpFaUserDataDTO fpFaUserData){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("delete fpFaUserData  begin .......");
			
			
			fpFaUserDataService.delete(fpFaUserData.getId());
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("delete fpFaUserData  end .......");
		}catch(Exception e){
			log.error("delete fpFaUserData error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	@RequestMapping("/updateFpFaUserData")
	@ResponseBody
	public ResultMap update(HttpServletRequest request, FpFaUserDataDTO fpFaUserData){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("update fpFaUserData  begin .......");
			
			
			DTOdateSet.setUpdateInfo(fpFaUserData,request.getSession());
			
			fpFaUserDataService.update(fpFaUserData);
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("update fpFaUserData list end .......");
		}catch(Exception e){
			log.error("update fpFaUserData error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	@RequestMapping("/updateForceFpFaUserData")
	@ResponseBody
	public ResultMap updateForce(HttpServletRequest request, FpFaUserDataDTO fpFaUserData){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("updateForce fpFaUserData  begin .......");
			
			
			DTOdateSet.setUpdateInfo(fpFaUserData,request.getSession());
			
			fpFaUserDataService.updateForce(fpFaUserData);
			
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("updateForce fpFaUserData list end .......");
		}catch(Exception e){
			log.error("updateForce fpFaUserData error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
}
